package main

import (
	"encoding/json"
	"fmt"
	"strings"

	"github.com/tidwall/gjson"
)

func main() {
	post := Post{1, "hello world", "rich"}
	b, err := json.Marshal(post)
	if err != nil {
		fmt.Println("error")
	}
	fmt.Println(string(b))

	// 第一个数组是 列 的长度
	// 数组中的值是 行 的长度

	json := `[{"name":{"first":"li","last":"dj"},"age":18},
	{"name":{"first":"aa","last":"bb"},"age":22} ,
	{"name":{"first":"cc","last":"dd"},"age":88} ,
	]`
	lastName := gjson.GetMany(json, "#.name.first", "#.age")
	fmt.Println(len(lastName))

	tempResult := [2][]string{}

	for i, v := range lastName {
		fmt.Println(i)
		fmt.Println(v)

		column := 0
		v.ForEach(func(key, value gjson.Result) bool {
			// fmt.Println(value.Index)
			fmt.Println(value)
			tempResult[i] = append(tempResult[i], value.String())
			column++
			return true
		})

	}

	fmt.Println(tempResult)

	realResult := make([][]string, len(tempResult[0]))
	for i, _ := range realResult {
		realResult[i] = make([]string, len(tempResult))
	}

	for i, v := range tempResult {
		for j, _ := range v {
			realResult[j][i] = tempResult[i][j]
		}
	}
	fmt.Println(realResult)

	for _, v := range realResult {
		// for _, v2 := range v {
		// 	fmt.Printf("%v,  ", v2)
		// }
		fmt.Println(strings.Join(v, ","))

		fmt.Println()
	}

	// lastName.ForEach(func(key, value gjson.Result) bool {
	// 	fmt.Println(value.Get("first"))
	// 	return true
	// })
}

type Post struct {
	Id      int    `json:"id"`
	Content string `json:"content"`
	Author  string `json:"auther name"`
}
